home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / plaintoo / plaintoo.py
Text File  |  2006-04-19  |  14KB  |  366 lines

  1. #!/usr/bin/python
  2.  
  3. # plaintoo, an app to grab the hashes with bkhive and samdump
  4. # written by Michael Zanetta grimmlin@pentoo.ch
  5. # Don't go further, it's ugly. Trust me, but, to quote pale_horse :
  6. # "Works is what matters, cute is for anals"
  7.  
  8. import sys
  9. import pygtk
  10. pygtk.require('2.0')
  11. import gtk, os
  12.  
  13. class RadioButtons:
  14.     def callback(self, widget, data=None):
  15.         print "%s was toggled %s" % (data, ("OFF", "ON")[widget.get_active()])
  16.  
  17.     def close_application(self, widget, event, data=None):
  18.         # Do some cleanup
  19.         if os.path.ismount('/mnt/plaintoo'):
  20.             os.system('umount /mnt/plaintoo')
  21.             if not os.path.ismount('/mnt/plaintoo'):
  22.                 os.system("rm -rf /mnt/plaintoo")
  23.         if os.path.isdir("/tmp/plaintoo"):
  24.             os.system("rm -rf /tmp/plaintoo")
  25.         gtk.main_quit()
  26.         return False
  27.  
  28.     def list_partitions(self):
  29.         list_partitions=""" #!/bin/sh
  30. PARTS=`cat /proc/partitions | grep [0-9]$ | sed -e 's/.* //g'`
  31. PARTSX=`cat /proc/partitions | grep [a-z]$ | sed -e 's/.* //g' -e '/name/d'`
  32. for x in $PARTSX
  33. do
  34. #    echo $PARTS 
  35. #    echo $PARTSX
  36.         TEMP=`fdisk -l /dev/$x | grep Ext | sed -e 's/ .*//g' -e 's/.*\///g'`
  37.         [ ! -z "${TEMP}" ] && PARTS=`echo $PARTS | sed -e 's:'$TEMP'::g'`
  38. done
  39. [ -e /var/tmp/part_found ] && rm /var/tmp/part_found
  40. #echo "next"
  41. for x in $PARTS
  42. do
  43.         VAR=`disktype /dev/$x | egrep -m 1 -e "(NTFS|FAT)" | grep -v Ext`
  44.         if [ ! "${VAR}" == ""  ]; then
  45.                 echo ${x} >> /var/tmp/part_found
  46.         fi
  47. done
  48. cat /var/tmp/part_found
  49. """
  50.         wrapper = open("/var/tmp/spawn.sh", "w")
  51.         wrapper.write(list_partitions)
  52.         wrapper.close()
  53.         cmd = "chmod a+x /var/tmp/spawn.sh && /var/tmp/spawn.sh"
  54.  
  55.         list = os.popen(cmd)
  56.         data = ""
  57.         data = os.read(list.fileno(),16384)
  58.         data.splitlines()
  59.         return data
  60.  
  61.     def list_dirs(self):
  62.         os.remove("/var/tmp/spawn.sh")
  63.         list_dir=""" #!/bin/sh
  64. find /mnt/plaintoo/ -type d -maxdepth 1 | sed -e 's/.*\///g'
  65. """
  66.         
  67.         wrapper = open("/var/tmp/spawn.sh", "w")
  68.         wrapper.write(list_dir)
  69.         wrapper.close()
  70.         cmd = "chmod a+x /var/tmp/spawn.sh && /var/tmp/spawn.sh"
  71.  
  72.         list = os.popen(cmd)
  73.         data = ""
  74.         data = os.read(list.fileno(),16384)
  75.         data.splitlines()
  76.         return data
  77.  
  78.     def spawn(self, cmd, return_output=False):
  79.         wrapper = open("/var/tmp/spawn.sh", "w")
  80.         wrapper.write("#!/bin/bash -l\n" + cmd + "\nexit $?\n")
  81.         wrapper.close()
  82.         if self._debug:
  83.             print cmd
  84.         cmd = "chmod a+x /var/tmp/spawn.sh && /var/tmp/spawn.sh"
  85.         ro_pipe = os.popen(cmd)
  86.         data = os.read(ro_pipe.fileno(),16384)
  87.         ret = ro_pipe.close() or 0
  88.  
  89.         if return_output:
  90.             return ret, data
  91.         else:
  92.             return ret
  93.  
  94.     def set_windir(self, widget, dir):
  95.         self.windir = dir
  96.         if self._debug:
  97.             print "Selected dir :" +dir
  98.         
  99.  
  100.     def test(self, part):
  101.         self.box2.destroy()
  102.         self.window.resize_children()
  103.         self.partitions_combo = gtk.combo_box_new_text()
  104.         found_dirs = ""
  105.         found_dirs = self.list_dirs().splitlines()
  106.         print found_dirs
  107.         for dir in found_dirs:
  108.             self.partitions_combo.append_text(dir)
  109.         if self._debug:
  110.             self.partitions_combo.connect("changed", self.get_active_text)
  111.         self.partitions_combo.set_active(0)
  112.  
  113.     def check_dir(self, part):
  114.         self.box2.destroy()
  115.         if self._debug:
  116.             print part
  117.         if not os.path.isdir('/mnt/plaintoo/'):
  118.             os.system('mkdir /mnt/plaintoo/')
  119.         if not os.path.ismount('/mnt/plaintoo'):
  120.             os.system('mount /dev/' + part + ' /mnt/plaintoo')
  121.         if not os.path.isdir('/mnt/plaintoo/' +  self.windir):
  122.             if self._debug:
  123.                 print self.windir + " does not exist"
  124.             # Delete and recreate the combobox listing dirs
  125.             content_str = """
  126.             
  127. The directory """ + self.windir + """ cannot be found.
  128. Please select amongst the following.
  129. """
  130.             content_label = gtk.Label(content_str)
  131.             
  132.             self.box2.destroy()
  133.             self.box2 = gtk.VBox(False, 10)
  134.             self.box2.pack_start(content_label, expand=False, fill=False, padding=0)
  135.             hbox = gtk.HBox(False, 10)
  136.             self.box2.pack_start(hbox, expand=False, fill=False, padding=0)
  137.             self.window.resize_children()
  138.             tmplabel = gtk.Label("Select dir :")
  139.             tmplabel.set_alignment(0.0, 0.5)
  140.             tmplabel.set_size_request(160, -1)
  141.             hbox.pack_start(tmplabel, expand=False, fill=False, padding=0)
  142.             self.partitions_combo = gtk.combo_box_new_text()
  143.             hbox.pack_start(self.partitions_combo, expand=False, fill=False, padding=0)
  144.             found_dirs = ""
  145.             found_dirs = self.list_dirs().splitlines()
  146.             print found_dirs
  147.             for dir in found_dirs:
  148.                 self.partitions_combo.append_text(dir)
  149.             
  150.             self.partitions_combo.connect("changed", self.set_new_windir)
  151.             self.partitions_combo.set_active(0)
  152.             self.partitions_combo.show()
  153.             self.box2.show_all()
  154.             #self.box2.show()
  155.             self.box1.pack_start(self.box2, expand=False, fill=False, padding=0)
  156.             self.box1.show_all()
  157.             #self.box1.show()
  158.  
  159.             
  160.             #TODO: Gerer le cas du unmount,
  161.             #os.system('umount /mnt/plaintoo')
  162.         else:
  163.             pathtoconf= "/mnt/plaintoo/" + self.windir + '/system32/config'
  164.             if self._debug:
  165.                 print "OK"
  166.             if not os.path.isdir(pathtoconf):
  167.                 return 1
  168.             else:
  169.                 exitstatus = self.spawn("bkhive " + pathtoconf + '/system /tmp/plaintoo/key')
  170.                 if exitstatus != 0:
  171.                     return 1
  172.                 if not os.path.isfile("/tmp/plaintoo/key"):
  173.                     return 1
  174.                 existatus, passlist = self.spawn("samdump2 " + pathtoconf + '/SAM /tmp/plaintoo/key 2>/dev/null', return_output=True)
  175.                 if len(passlist) < 10:
  176.                     passlist = "Could not grab any hashes..."
  177.                 if self._debug:
  178.                     print passlist
  179.                 self.button_next.destroy()
  180.             content_str = """
  181.             
  182. Here are the hashes found.
  183. """
  184.             content_label = gtk.Label(content_str)
  185.             
  186.             self.box2.destroy()
  187.             self.box2 = gtk.VBox(False, 40)
  188.             self.box2.pack_start(content_label, expand=False, fill=False, padding=0)
  189.             self.logtextbuff = gtk.TextBuffer()
  190.             self.logtextbuff.set_text(passlist)
  191.             self.logtextview = gtk.TextView(self.logtextbuff)
  192.             self.logtextview.set_editable(False)
  193.             self.logtextviewscroll = gtk.ScrolledWindow()
  194.             self.logtextviewscroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
  195.             self.logtextviewscroll.add(self.logtextview)
  196.             self.box2.pack_start(self.logtextviewscroll, expand=True, fill=True)
  197.             # Add the button for FF -> plain-text.info
  198.             buttonbox = gtk.HBox(False, 10)
  199.             button_pt = gtk.Button()
  200.             buttonlabel = gtk.Label("Crack online")
  201.             buttonlabel.set_use_underline(True)
  202.             buttonimg = gtk.Image()
  203.             buttonimg.set_from_file('./img/pt.png')
  204.             buttonbox.pack_start(buttonimg)
  205.             buttonbox.pack_start(buttonlabel)
  206.             button_pt.add(buttonbox)
  207.             button_pt.connect_object("clicked", self.open_ff, None)
  208.             fill = gtk.HBox(False,10)
  209.             
  210.             container = gtk.HBox(False, 10)
  211.             container.pack_start(fill, expand=True, fill=True, padding=0)
  212.             container.pack_start(button_pt, expand=False, fill=False, padding=0)
  213.             fill = gtk.HBox(False,10)
  214.             container.pack_start(fill, expand=True, fill=True, padding=0)
  215.             container.show_all()
  216.             
  217.             self.box2.pack_start(container, expand=False, fill=False, padding=0)
  218.             self.box2.show_all()
  219.             self.box1.pack_start(self.box2, expand=False, fill=False, padding=0)
  220.             self.box1.show_all()
  221.             
  222.     def open_ff(self, toto):
  223.         os.system("firefox http://www.plain-text.info/")
  224.  
  225.     def get_active_text(self, combobox):
  226.         data = ""
  227.         model = combobox.get_model()
  228.         index = combobox.get_active()
  229.         data = model[index][0]
  230.         if self._debug:
  231.             print "Selected disk: " + data
  232.         self.check_dir(data)
  233.         return data
  234.  
  235.     def set_new_windir(self, combobox):
  236.         data = ""
  237.         model = combobox.get_model()
  238.         index = combobox.get_active()
  239.         data = model[index][0]
  240.         if self._debug:
  241.             print "Selected new dir: " + data
  242.         self.windir = data
  243.  
  244.  
  245.     def __init__(self):
  246.         if not os.path.isdir("/tmp/plaintoo"):
  247.             os.system("mkdir /tmp/plaintoo")
  248.         self.windir = "WINNT"
  249.         self._debug=False
  250.         
  251.         for arg in sys.argv:
  252.             if arg == "-d" or arg == "--debug":
  253.                 self._debug = True
  254.  
  255.         # Construct window
  256.         self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  257.         self.window.connect("delete_event", self.close_application)
  258.         self.window.set_title("Grab the hash with plaintoo/plain-text.info")
  259.         self.window.set_border_width(0)
  260.         self.window.set_default_size(400,400)
  261.         self.window.set_geometry_hints(None, min_width=400, min_height=400, max_width=400, max_height=400)
  262.         
  263.  
  264.         # Banner image
  265.         animpixbuf = gtk.gdk.PixbufAnimation('./img/plaintoo.gif')
  266.         image = gtk.Image()
  267.         image.set_from_animation(animpixbuf)
  268.         image.show()
  269.  
  270.         self.box1 = gtk.VBox(False, 0)
  271.         self.window.add(self.box1)
  272.         self.box1.pack_start(image, expand=False, fill=False, padding=0)
  273.  
  274.         content_str = """Please select wich windows version you want to grab
  275. the hashes from.
  276. """
  277.         content_label = gtk.Label(content_str)
  278.         
  279.  
  280.         self.box2 = gtk.VBox(False, 10)
  281.         self.box2.set_border_width(10)
  282.         self.box2.pack_start(content_label, expand=False, fill=False, padding=10)
  283.         content_label.show()
  284.         self.box1.pack_start(self.box2, expand=False, fill=False, padding=10)
  285.         self.box1.show()
  286.         self.box2.show()
  287.          
  288.         button = gtk.RadioButton(None, "Windows XP/2003")
  289.         button.set_name("Windows XP or Windows 2003")
  290.         button.connect("toggled", self.set_windir, "WINDOWS")
  291.         self.box2.pack_start(button, expand=False, fill=False, padding=0)
  292.         button.show()
  293.  
  294.         button = gtk.RadioButton(button, "Windows 2000/NT 4")
  295.         button.connect("toggled", self.set_windir, "WINNT")
  296.         button.set_active(True)
  297.         self.box2.pack_start(button, expand=False, fill=False, padding=0)
  298.         button.show()
  299.         
  300.  
  301.         hbox = gtk.HBox(False, 0)
  302.         tmplabel = gtk.Label("Select Drive:")
  303.         tmplabel.set_alignment(0.0, 0.5)
  304.         tmplabel.set_size_request(160, -1)
  305.         hbox.pack_start(tmplabel, expand=False, fill=False, padding=0)
  306.         self.partitions_combo = gtk.combo_box_new_text()
  307.         hbox.pack_start(self.partitions_combo, expand=False, fill=False, padding=0)
  308.         found_parts = ""
  309.         found_parts = self.list_partitions().splitlines()
  310.         for device in found_parts:
  311.             self.partitions_combo.append_text(device)
  312.         #if self._debug:
  313.             #self.partitions_combo.connect("changed", self.get_active_text)
  314.         self.partitions_combo.set_active(0)
  315.         #self.partitions_combo.set_text_column(0)
  316.  
  317.         hbox.show_all()
  318.         hbox.show()
  319.         self.box2.pack_start(hbox, expand=False, fill=False, padding=15)
  320.  
  321.         self.bottom_box = gtk.HBox(False, 10)
  322.         self.bottom_box.set_border_width(10)
  323.         self.box1.pack_end(self.bottom_box, expand=False, fill=False, padding=0)
  324.         separator = gtk.HSeparator()
  325.         self.bottom_box.pack_start(separator, expand=False, fill=False, padding=0)
  326.         separator.show()
  327.         self.bottom_box.show_all()
  328.  
  329.         buttonbox = gtk.HBox(False, 10)
  330.         button_close = gtk.Button()
  331.         buttonlabel = gtk.Label("Quit")
  332.         buttonlabel.set_use_underline(True)
  333.         buttonimg = gtk.Image()
  334.         buttonimg.set_from_file('./img/stock_exit.png')
  335.         buttonbox.pack_start(buttonimg)
  336.         buttonbox.pack_start(buttonlabel)
  337.         button_close.add(buttonbox)
  338.         button_close.connect_object("clicked", self.close_application, self.window,
  339.                               None)
  340.         
  341.         buttonbox = gtk.HBox(False, 10)
  342.         self.button_next = gtk.Button()
  343.         buttonlabel = gtk.Label("Next")
  344.         buttonlabel.set_use_underline(True)
  345.         buttonimg = gtk.Image()
  346.         buttonimg.set_from_file('./img/stock_right.png')
  347.         buttonbox.pack_start(buttonimg)
  348.         buttonbox.pack_start(buttonlabel)
  349.         self.button_next.add(buttonbox)
  350.         self.button_next.connect_object("clicked", self.get_active_text, self.partitions_combo)
  351.         self.bottom_box.pack_start(button_close, expand=False, fill=False, padding=5)
  352.         self.bottom_box.pack_end(self.button_next, expand=False, fill=False, padding=5)
  353.         button.set_flags(gtk.CAN_DEFAULT)
  354.         button.grab_default()
  355.         self.bottom_box.show_all()
  356.         self.window.show()
  357.         
  358.  
  359. def main():
  360.     gtk.main()
  361.     return 0        
  362.  
  363. if __name__ == "__main__":
  364.     RadioButtons()
  365.     main()
  366.